package com.lyb.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.lyb.spzx.manager.service.SysRoleService;
import com.lyb.spzx.model.dto.system.system.SysRole;
import com.lyb.spzx.model.vo.common.Result;
import com.lyb.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 角色
 */
@Tag(name = "角色接口")
@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @Operation(summary = "分页查询角色")
    @GetMapping("/findByPage")
    public Result<PageInfo<SysRole>> findByPage(@RequestParam(defaultValue = "1")  Integer pageNum,
                                                @RequestParam(defaultValue = "10")  Integer pageSize,
                                                String keyword){
        PageInfo<SysRole> pageInfo = sysRoleService.findByPage(keyword,pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加角色")
    @PostMapping("/saveSysRole")
    public Result saveRole(@RequestBody SysRole sysRole){
        sysRoleService.saveSysRole(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改角色")
    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole){
        sysRoleService.updateSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "删除角色")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteRole(@PathVariable(name = "id") Integer id){
        sysRoleService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询所有角色")
    @GetMapping("/findAllRoles/{id}")
    public Result<Map<String,Object>> findAll(@PathVariable Long id){
        Map<String, Object> map = sysRoleService.findAll(id);
        return Result.build(map,ResultCodeEnum.SUCCESS);
    }
}
